trigger CXGFetchCampaignMemberOwnerManager on CXG_Campaign_Accounts__c (before Insert,before Update) {
    Set<Id> user_id = new Set<Id>();
    //QueueSobject agentqueueId = [Select QueueId from QueueSobject where Queue.Name ='Agent Queue' LIMIT 1];
    //QueueSobject controlgrpQueueId=[Select QueueId from QueueSobject where Queue.Name ='Control Group Queue' Limit 1];
    //QueueSobject holdingQueueId=[Select QueueId from QueueSobject where Queue.Name ='Holding Queue' Limit 1];
    
    QueueSobject agentqueueId = CXGCampaignStart.agentqueueId;
    QueueSobject controlgrpQueueId = CXGCampaignStart.controlgrpQueueId;
    QueueSobject holdingQueueId = CXGCampaignStart.holdingQueueId;
    //system.debug('Current SOQL count: ' + Limits.getQueries());
    ID CxGCampaignMemberRecordTypeId = RecordTypeHelper.GetRecordTypeIdByDevName('CXG_Campaign_Accounts__c', 'Campaign_Member');         
       for(CXG_Campaign_Accounts__c cm :Trigger.New) {
            if(Trigger.isInsert ||Trigger.isUpdate)
             {
                
                if(cm.RecordTypeId==CxGCampaignMemberRecordTypeId && cm.OwnerId!=null && cm.IscampaignActive__c==True)
                {
                    user_id.add(cm.OwnerId); 
                }
             }
        }
    System.Debug('SIZE'+user_id.Size());
    if(user_id.size()>0)
    {
      Map<Id,User> usrs = New Map<Id,User>();
      for(User usr:[Select Id,Name,ManagerId from User where Id IN: user_id]){  
            if(usr.ManagerId!=null)
                {
                    usrs.put(usr.Id,usr);
                } 
             
            }
         for(CXG_Campaign_Accounts__c cm :Trigger.New)  { 
               try  
                 {
                     if((cm.OwnerId==agentqueueId.QueueId ||cm.OwnerId==controlgrpQueueId.QueueId|| cm.OwnerId==holdingQueueId.QueueId)&& cm.RecordTypeId==CxGCampaignMemberRecordTypeId)
                     {
                         cm.Owner_Manager__c=null;
                     }
                     else
                     {   
                         
                         cm.Owner_Manager__c= usrs.get(cm.OwnerId).ManagerId;
                     }
                 }  
               catch(Exception exe)  
                    {   
                         system.Debug(exe);  
                    }        
      }
}}